﻿using System;
using System.Collections.Generic;
using System.Linq;
using SeaBattle.Domain.Abstract;
using SeaBattle.Domain.Entities;

namespace SeaBattle.Domain.Concrete
{
    public class GameRepository : IGameRepository
    {
        private static readonly List<Game> Games = new List<Game>();

        private static int GetNextId()
        {
            return Games.Count + 1;
        }

        public IEnumerable<Game> GetAllGames()
        {
            return Games.AsEnumerable();
        }


        public Game CreateNewGame(string name, Player creator)
        {
            return new Game(GetNextId(), name, DateTime.Now, creator);
        }

        public bool SaveGame(Game game)
        {
            if (!Games.Contains(game))
            {
                Games.Add(game);
            }
            return true;
        }
    }
}
